import { defineStore } from "pinia";
import { ref } from "vue";


export const useUserStore = defineStore('userInfo', () => {
    const userInfo = ref({
        ...JSON.parse(localStorage.getItem('userInfo') || '{}'),
    });

    // 设置信息
    function setUserInfo(user: any) {
        console.log(user);
        userInfo.value = user;
        localStorage.setItem('userInfo', JSON.stringify(user));
    }

    // 获取信息
    function getUserInfo() {
        return userInfo.value;
    }

    return {
        userInfo,
        setUserInfo,
        getUserInfo,
    }
});